package gg

import (
	"gitee.com/injoyai/goutil/conv"
	"gitee.com/injoyai/goutil/g/in"
	"gitee.com/injoyai/goutil/i/html"
	"gitee.com/injoyai/goutil/net/router"
	"gitee.com/injoyai/goutil/string/logs/v1"
)

type Server struct {
	*router.Server
}

func New(ports ...int) *Server {
	port := conv.GetDefaultInt(8000, ports...)
	s := router.New().SetPort(port)
	in.InitRoute(s)
	s.Bind.Set(404, func(r *router.Request) {
		r.WriteString(html.PageNotFindRobot)
	})
	return &Server{
		Server: s,
	}
}

func (s *Server) ALL(pattern string, handler router.Handler) *Server {
	s.Server.ALL(pattern, handler)
	return s
}

func (s *Server) GET(pattern string, handler router.Handler) *Server {
	s.Server.GET(pattern, handler)
	return s
}

func (s *Server) POST(pattern string, handler router.Handler) *Server {
	s.Server.POST(pattern, handler)
	return s
}

func (s *Server) PUT(pattern string, handler router.Handler) *Server {
	s.Server.PUT(pattern, handler)
	return s
}

func (s *Server) DELETE(pattern string, handler router.Handler) *Server {
	s.Server.DELETE(pattern, handler)
	return s
}

func (s *Server) Run() {
	logs.PrintErr(s.Server.Run())
}
